package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :  LENOVO
 * 创建时间 : 2024/6/8 16:43
 */
@RestController
@Slf4j
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //    新增菜品类型
    @ApiOperation("添加菜品类型")
    @PostMapping
    public Result<Category> add(@RequestBody CategoryDTO categoryDTO) {
        categoryService.insert(categoryDTO);
        return Result.success();
    }

    //    删除菜品类型
    @ApiOperation("删除功能")
    @DeleteMapping
    public Result<String> delete(Long id) {
        categoryService.delete(id);
        return Result.success();
    }

    //    分页查询
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.categoryQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    //    修改状态
    @ApiOperation("修改状态")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        categoryService.start0rStop(status, id);
        return Result.success();
    }

    //    修改菜品类型
    @ApiOperation("分类修改")
    @PutMapping
    public Result<Category> update(@RequestBody CategoryDTO categoryDTO) {
        categoryService.update(categoryDTO);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     *
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type) {
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
